public class maxProfit {
    public int maxProfit(int[] prices){
        if(prices == null || prices.length <= 1){
            return 0;
        }
        int a = Integer.MAX_VALUE;
        int b = 0;
        for(int price : prices){
            a = Math.min(a,price);
            b = Math.max(b,price - a);
        }
        return b;
    }
}
